<?php

namespace App\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Foundation\Events\Dispatchable;

class PodcastProcessed implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $channelUUID;

    /**
     * Create a new event instance.
     */
    public function __construct($channelUUID)
    {
        $this->channelUUID   = $channelUUID;
    }


    public function broadcastOn(): array
    {
        Log::info('广播频道 - 私有频道 : Test.Channel.' . $this->channelUUID);
//        return [
//            new PrivateChannel('Test.Channel.'.$this->channelUUID),
//        ];
        return [
            new PublicChannel('Test.Channel.'.$this->channelUUID),
        ];
    }

    /**
     * 事件的广播名字
     * @return string
     */
    public function broadcastAs(): string
    {
        Log::info('事件的广播名字 : test.name');
        return 'test.name';
    }

    /**
     * 获取将要广播的数据
     *
     * @return array<string, mixed>
     */
    public function broadcastWith(): array
    {
        $data = ['Message' => '我是测试数据'];
        Log::info('获取将要广播的数据: ' . $data);
        return $data;
    }
}
